package tau_sadna.tau_map;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html.ImageGetter;
import android.util.Log;

public class ResourceImageGetter implements ImageGetter {

	private Context context;

	ResourceImageGetter(Context cxt) {
		context = cxt;
	}
	
	@Override
	public Drawable getDrawable(String imgName) {
		Log.i("ResourceImageGetter","Looking for resource "+imgName);
		while (imgName.endsWith("/"))
			imgName = imgName.substring(0, imgName.length()-1);
		Log.i("ResourceImageGetter","Stripped name: "+imgName);
		int resId = context.getResources().getIdentifier(imgName, "drawable", "tau_sadna.tau_map");
		Drawable drawable = context.getResources().getDrawable(resId);
		drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
		Log.i("ResourceImageGetter","Image dimensions: "+drawable.getIntrinsicWidth()+" "+drawable.getIntrinsicHeight());
		return drawable;
		
	}

}
